<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <link rel="stylesheet" href="./css/login.css" />
  <title>Document</title>
</head>

<body>
  <div class="loginContainer">
    <h1>登录</h1>
    <form enctype="application/x-www-form-urlencoded" action="" method="post" onsubmit="return false">
        姓名：
      <input class="inputStyle1 inputStyle username" type="text" name="username" />
      <span class="exchange">用户名不正确</span>
      <br />密码：
      <input class="inputStyle pwd" type="password" name="pwd" /><br />
	   记住我 <input type="checkbox" class="remeber" />
      <input class="loginStyle btn" type="submit" value="登录" />
    </form>
  </div>
</body>
<script>
    let usernameEle = document.querySelector(".username");
    let pwdEle = document.querySelector(".pwd");
    let btnEle = document.querySelector(".btn");
    btnEle.onclick = function(){
        // eslint:代码风格控制
        let username = usernameEle.value;
        let pwd = pwdEle.value;
        let xhr  = new XMLHttpRequest();
        xhr.open("post","/admin/checkuser");
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
        xhr.onload = function(){
            // console.log(xhr.responseText);
            let res = JSON.parse(xhr.responseText);
            if(res.status==1){
                console.log(res.message);
                // 跳转到添加新闻的页面
                window.location.href = "/admin/addnews";
            }
        }
        let str = `username=${username}&pwd=${pwd}`
        xhr.send(str);
    }

</script>
</html>